<?php
/**
 * Description of supervisor
 *
 * @author Henson
 */
class Supervisor extends Base{
	
	private $supervisorTable = "tbl_supervisor";
	
	public function insertSupervisor($insertArr)
	{
		$insertArr['insert_time'] = time();
		$insertArr['del'] = '0';
		return $this->db->insert($insertArr, $this->supervisorTable);
	}
	
	public function updateSupervisor($updateArr, $uid)
	{
		$updateArr['update_time'] = time();
		$where = " where id=".$uid;
		return $this->db->update($updateArr, $this->supervisorTable, $where);
	}
	
	public function getSupervisorByLoginname($loginname)
	{
		$sql = "select * from {$this->supervisorTable} where loginname='".$loginname."' limit 1";
		return $this->db->loadRow($sql);
	}
	
	public function getSupervisorById($sid)
	{
		$sql = "select * from {$this->supervisorTable} where id='".$sid."' limit 1";
		return $this->db->loadRow($sql);
	}

	public function getSupervisorTotal()
	{
		$where = "where del='0' and loginname!= 'admin'";
		return $this->getTotalNum($this->supervisorTable, $where);
	}
	
	public function getSupervisorList($where, $orderBy='', $limit='')
	{
		$sql = "select * from {$this->supervisorTable} {$where} {$orderBy} {$limit}";
		$this->db->setQuery($sql);
		return $this->db->loadAssocList();
	}
	
	public function dealSupervisor($supervisor)
	{
		global $_CFG;
		$supervisor['permission_checked'] = explode(',', $supervisor['permission']);
		
		if($supervisor['loginname'] == 'admin')
		{
			$supervisor['permission_show'] = "所有权限";
		}
		else
		{
			$tempArr = array();
			foreach($supervisor['permission_checked'] as $permissionKey)
			{
				$tempArr[] = $_CFG['permissionShow'][$permissionKey];
			}
			$supervisor['permission_show'] = implode('<br/>', $tempArr);
			unset($tempArr);
		}
		
		$cell_phone_arr = explode('-', $supervisor['cell_phone']);
		$supervisor['cell_phone1'] = $cell_phone_arr[0];
		$supervisor['cell_phone2'] = $cell_phone_arr[1];
		$office_phone_arr = explode('-', $supervisor['office_phone']);
		$supervisor['office_phone1'] = $office_phone_arr[0];
		$supervisor['office_phone2'] = $office_phone_arr[1];
		$email_arr = explode('@', $supervisor['email']);
		$supervisor['email1'] = $email_arr[0];
		$supervisor['email2'] = $email_arr[1];
		
		return $supervisor;
	}
}
?>